$(function() {
  $(".navbar-expand-toggle").click(function() {
    $(".app-container").toggleClass("expanded");
    return $(".navbar-expand-toggle").toggleClass("fa-rotate-90");
  });
  return $(".navbar-right-expand-toggle").click(function() {
    $(".navbar-right").toggleClass("expanded");
    return $(".navbar-right-expand-toggle").toggleClass("fa-rotate-90");
  });

});
$.fn.loading = function(type,txt){
  var _this = this
  var _txt = txt?txt:'提交中，请稍候'
  var _loader = `<div class="loader-container text-center color-white">
      <div><i class="fa fa-spinner fa-pulse fa-3x"></i></div>
              <div>${_txt}</div>
      </div>`
  if(type == 'open'){
      _this.addClass('loader')
      _this.append($(_loader))
  }else if(type == 'close'){
      _this.removeClass('loader')
      $('.loader-container').remove()
      // $('.loader').removeClass('loader')
  }      
}
$(function(){
  $('body').loading('open','加载中')
})
$('body').loading('open','加载中')
var serverUrl={
  base:'http://119.23.232.192:8081/',
  // base:'http://10.87.140.204:8081/',
  login:'Organization/user/login',
  count:'Grid/Count/',
  organize:'Organization/organize/',
  department:'Organization/department/',
  importbatch:'Organization/Importsave/',
  informationType:'Organization/information/',
  user:'Organization/user/',
  post:'Organization/post/',
  quantification:'Quantification/Quantification/',
  grid:'Organization/grid/',
  device:'Device/device/',
  taskTrainStation:'Organization/station/',
  taskTrain:'Organization/train/',
  mapUrl:'',
  workTask:'Worktask/Worktask/'
}

var select2Datas = {
  trainCycle:[
    {id:'1',text:'每天'},
    {id:'2',text:'隔日'},
    {id:'3',text:'每周'},
    {id:'4',text:'开一停二'},
    {id:'5',text:'开二停一'}
  ],
  task:[
    {id:'1',text:'作业流程1'},
    {id:'2',text:'作业流程2'},
    {id:'3',text:'作业流程3'},
    {id:'4',text:'作业流程4'}
  ],
  gridTips:[
    {id:'1',text:'站台区'},
    {id:'2',text:'候车区'},
    {id:'3',text:'厕所'},
    {id:'4',text:'售票厅'}
  ],
  tempGrid:[
    {id:'1',text:'候车室1'},
    {id:'2',text:'候车室2'},
    {id:'3',text:'候车室3'},
    {id:'4',text:'候车室4'},
    {id:'5',text:'候车室5'},
    {id:'6',text:'候车室6'}
  ],
  quantiRate:[
    {id:'2',text:'2小时巡视'},
    {id:'6',text:'6小时巡视'},
    {id:'8',text:'8小时巡视'},
    {id:'12',text:'12小时巡视'}
  ],
  day:[
    {id:'0',text:'0天'},
    {id:'1',text:'1天'},
    {id:'2',text:'2天'},
    {id:'3',text:'3天'},
    {id:'4',text:'4天'},
    {id:'5',text:'5天'},
    {id:'6',text:'6天'},
    {id:'7',text:'7天'},
    {id:'8',text:'8天'},
    {id:'9',text:'9天'},
    {id:'10',text:'10天'},
    {id:'11',text:'11天'},
    {id:'12',text:'12天'},
    {id:'13',text:'13天'},
    {id:'14',text:'14天'},
    {id:'15',text:'15天'},
    {id:'16',text:'16天'},
    {id:'17',text:'17天'},
    {id:'18',text:'18天'},
    {id:'19',text:'19天'},
    {id:'20',text:'20天'},
    {id:'21',text:'21天'},
    {id:'22',text:'22天'},
    {id:'23',text:'23天'},
    {id:'24',text:'24天'},
    {id:'25',text:'25天'},
    {id:'26',text:'26天'},
    {id:'27',text:'27天'},
    {id:'28',text:'28天'},
    {id:'29',text:'29天'},
    {id:'30',text:'30天'}
  ],
  hour:[
    {id:'0',text:'0小时'},
    {id:'1',text:'1小时'},
    {id:'2',text:'2小时'},
    {id:'3',text:'3小时'},
    {id:'4',text:'4小时'},
    {id:'5',text:'5小时'},
    {id:'6',text:'6小时'},
    {id:'7',text:'7小时'},
    {id:'8',text:'8小时'},
    {id:'9',text:'9小时'},
    {id:'10',text:'10小时'},
    {id:'11',text:'11小时'},
    {id:'12',text:'12小时'},
    {id:'13',text:'13小时'},
    {id:'14',text:'14小时'},
    {id:'15',text:'15小时'},
    {id:'16',text:'16小时'},
    {id:'17',text:'17小时'},
    {id:'18',text:'18小时'},
    {id:'19',text:'19小时'},
    {id:'20',text:'20小时'},
    {id:'21',text:'21小时'},
    {id:'22',text:'22小时'},
    {id:'23',text:'23小时'},
    {id:'24',text:'24小时'}
  ],
  xjcycle:[
    {id:'1',text:'1天1次'},
    {id:'2',text:'7天1次'},
    {id:'3',text:'30天1次'}
  ]
}
var vueStore={
  state:{
    serverUrl:serverUrl,
    select2Datas:select2Datas
  },
  setSelId:function(id){
      this.state.selId = id
  }
}
// $(function() {
//    return $('select.select').select2();
// });

$(function() {
  return $('.toggle-checkbox').bootstrapSwitch({
    size: "small"
  });
});

$(function() {
  return $('.match-height').matchHeight();
});

$(function() {
  return $('.datatable').DataTable({
    "dom": '<"top"fl<"clear">>rt<"bottom"ip<"clear">>',
    language:{
      url: '../lib/js/cn_lang.json'
    }
  })
   
});
/*12-24 jquery nav */
// $(function(){
//   $('.side-menu-container .nav .panel').on('click',function(){
//     var _txt = $(this).find('a').attr('href').split('#')[1]
//     $(this).addClass('active').siblings('.panel').removeClass('active')
//     $('.nav-bar2').find('.panel-collapse').each(function(ids,elm){
      
//       if($(elm).attr('id') == _txt){
//         $(elm).addClass('in')
//       }else{
//         console.log('xx')
//         $(elm).removeClass('in')
//       }
//     })
    
//   })

// })
/*12-24  nav  old*/
// $(function() {
//   return $(".side-menu .nav .dropdown").on('show.bs.collapse', function() {
//     return $(".nav-bar2 .collapse").collapse('hide'),$(".side-menu .nav .dropdown .collapse").collapse('hide');
//   });
// });
// $(function() {
//   return $(".side-menu .nav .dropdown").on('click', function() {
//     var _text=$(this).find('.title').text()
//     $(this).addClass('active').siblings('.dropdown').removeClass('active')
//     $(".nav-bar2 .title").text(_text)
//     $(".nav-bar2 .collapse").collapse('hide');
//   });
// });

var storageControl={
    storagable:function(){
        if (typeof(Storage) !== "undefined") {
            return true
         }else{
            console.log("抱歉！您的浏览器不支持 Web Storage ...");
            return false
         }
    },
    islogined:function(){
        if(this.storagable()){
            var _uid = localStorage.getItem('user_id') || ''
            if(_uid == ''){
                window.location.href='./login.html';
            }

        }
    },
    clear:function(){
        if(this.storagable()){
            //var _uid = localStorage.getItem('user_id') || ''
            localStorage.clear();
            sessionStorage.clear();
        }
    },
    setStorage:function(data){
        if(this.storagable()){
            for(var i in data){
                localStorage.setItem(i, data[i]);
            }
        }
    },
    isloginedS:function(){
        if(this.storagable()){
            var _uid = sessionStorage.getItem('user_id') || ''
            if(_uid == ''){
                window.location.href='./login.html';
            }

        }
    },
    setStorageS:function(data){
        if(this.storagable()){
            for(var i in data){
                sessionStorage.setItem(i, data[i]);
            }
        }
    }
}
storageControl.isloginedS()
var powers={
    mapUserLoation:false,//'25','允许：在PC端查看员工定位'
    infoTypeManage:false,//'107','允许：管理上报类型'
    taskTrainControl:false,//'108','允许：在PC端和移动端查看“作业安全控制”的内容'
    emergencyStart:false,//'109','允许：在PC端下达“应急处置”事件'
    emergencyManage:false,//'110','允许：管理应急处置注意事项及流程'
    deviceManage:false,//'111','允许：在PC端和移动端查看设备信息'
    deviceManageXJ:false,//'112','允许：在PC端下达设备巡检任务'
    deviceManageWX:false,//'113','允许：在PC端下达设备维修任务'
    deviceManageDt:false,//'114','允许：管理“设备信息管理”及“设备巡检管理”
    trainManage:false,//'128','允许：管理“列车站台管理”及“列车信息管理”
    countTask:false,//'132','允许 : 查看任务统计
    organizationPostManage:false,//'144','允许：操作作业岗位'
    taskBaseManage:false,//'143','允许：操作作业岗位'
    taskFlowManage:false,//'146','允许：操作作业流程'
    upInfoRecord:false,//'150','允许：查看上报处理记录'
    mapWorkerLocationSearch:false,//'155','允许：使用员工定位查询功能'
}
function initPower(){
  var _islocal = storageControl.storagable()
  if(_islocal){
      var _power = ['25','109']
    //   var _power = sessionStorage.getItem('power').split(',')
      for(var i=0;i<_power.length;i++){
        switch(_power[i]){
          case '25':
            //'25','允许：在PC端查看员工定位'
            powers.mapUserLoation = true
          break;
          case '107':
            //'107','允许：管理上报类型'
            powers.infoTypeManage = true
          break;
          case '108':
            //'108','允许：在PC端和移动端查看“作业安全控制”的内容'
            powers.taskTrainControl = true
          break;
          case '109':
            //'109','允许：在PC端下达“应急处置”事件'
            powers.emergencyStart = true
          break;
          case '110':
            //'110','允许：管理应急处置注意事项及流程'
            powers.emergencyManage = true
          break;
          case '111':
            //'111','允许：在PC端和移动端查看设备信息'
            powers.deviceManageDt = true
          break;
          case '112':
            //'112','允许：在PC端下达设备巡检任务'
            powers.deviceManageXJ = true
          break;
          case '113':
            //'113','允许：在PC端下达设备维修任务'
            powers.deviceManageWX=true
          break;
          case '114':
            //'114','允许：管理“设备信息管理”及“设备巡检管理”
            powers.deviceManage=true
          break;
          case '128':
            //'128','允许：管理“列车站台管理”及“列车信息管理”
            powers.trainManage=true
          break;
          case '132':
            //'132','允许 : 查看任务统计'
            powers.countTask=true
          break;
          case '143':
            //'143','允许：操作作业岗位'
            powers.taskBaseManage=true
          break;
          case '144':
            //'144','允许：操作作业岗位'
            powers.organizationPostManage=true
          break;
          case '146':
             //'146','允许：操作作业流程'
            powers.taskFlowManage=true
          break;
          case '150':
            //'150','允许：查看上报处理记录'
            powers.upInfoRecord=true
          break;
          case '155':
            //'155','允许：使用员工定位查询功能'
            powers.mapWorkerLocationSearch=true
          break;
          case '2':
            powers.deviceTaskTransmit = true
            powers.deviceTaskGiveUp = true
          break;
        }
      }
  }
  console.log(powers)
}
initPower()
Vue.component('side-menu',{
  /*    template:`<div class="side-menu sidebar-inverse">
                  <nav class="navbar navbar-default" role="navigation">
                      <div class="side-menu-container">
                          <div class="navbar-header">
                              <a class="navbar-brand" href="">
                                  <div class="icon fa fa-train"></div>
                                  <div class="title">北京站</div>
                              </a>
                              <button type="button" class="navbar-expand-toggle pull-right visible-xs">
                                  <i class="fa fa-times icon"></i>
                              </button>
                          </div>
                          <ul class="nav navbar-nav">
                              <li v-for="(info,index) in nav1" :key="info.id" :rel="info.type" @click="showNav2(info.type)" :class="{active:info.type == accNav1}">
                                  <a href="javascript:void(0)">
                                      <span class="icon fa" :class="info.fa"></span><span class="title">{{info.name}}</span>
                                  </a>
                              </li>
                          </ul>
                          
                      </div>
                  </nav> 
                  <div class="nav-bar2">
                      <div class="navbar-title">
                          <p class="title">组织管理</p>
                      </div>
                      <div class="panel-collapse collapse in" aria-expanded="true">
                          <ul class="nav navbar-nav">
                              <li v-for="(info,index) in nav2" v-if="info.type == accNav1">
                                  <a :href="info.url">{{info.name}}</a>
                              </li>
                          </ul>
                      </div>
                  </div>
              </div>`,
  */
    template:'<div class="side-menu sidebar-inverse">\
                <nav class="navbar navbar-default" role="navigation">\
                    <div class="side-menu-container">\
                        <div class="navbar-header">\
                            <a class="navbar-brand" href="">\
                                <div class="icon fa fa-train"></div>\
                                <div class="title">北京站</div>\
                            </a>\
                            <button type="button" class="navbar-expand-toggle pull-right visible-xs">\
                                <i class="fa fa-times icon"></i>\
                            </button>\
                        </div>\
                        <ul class="nav navbar-nav">\
                            <li v-for="(info,index) in nav1" :key="info.id" :rel="info.type" @click="showNav2(info.type)" :class="{active:info.type == accNav1}">\
                                <a href="javascript:void(0)">\
                                    <span class="icon fa" :class="info.fa"></span><span class="title">{{info.name}}</span>\
                                </a>\
                            </li>\
                        </ul>\
                    </div>\
                </nav> \
                <div class="nav-bar2">\
                    <div class="navbar-title">\
                        <p class="title">{{nav1Name}}</p>\
                    </div>\
                    <div class="panel-collapse collapse in" aria-expanded="true">\
                        <ul class="nav navbar-nav">\
                            <li v-for="(info,index) in nav2" v-if="info.type == accNav1">\
                                <a :href="info.url">{{info.name}}</a>\
                            </li>\
                        </ul>\
                    </div>\
                </div>\
            </div>',
    data:function(){
        return navData
    },
    methods:{
        showNav2:function(type){
            this.accNav1=type
        }
    }
})
Vue.component('top-nav',{
  template:'<ul class="nav navbar-nav navbar-left no-border">\
              <li v-for="(info,index) in nav3" v-if="info.type == accNav2" :key="info.id" :class="{active:accNav3 == info.id}"><a :href="info.url" role="button">{{info.name}}</a></li>\
            </ul>',
  data:function(){
    return navData
  }
})
Vue.component('right-info',{
  
  template:`<ul class="nav navbar-nav navbar-right" style="display:none">
    <button type="button" class="navbar-right-expand-toggle pull-right visible-xs">
        <i class="fa fa-times icon"></i>
    </button>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-comments-o"></i></a>
        <ul class="dropdown-menu animated fadeInDown">
            <li class="title">
                Notification <span class="badge pull-right">0</span>
            </li>
            <li class="message">
                No new notification
            </li>
        </ul>
    </li>
    <li class="dropdown danger">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-star-half-o"></i> 4</a>
        <ul class="dropdown-menu danger  animated fadeInDown">
            <li class="title">
                Notification <span class="badge pull-right">4</span>
            </li>
            <li>
                <ul class="list-group notifications">
                    <a href="#">
                        <li class="list-group-item">
                            <span class="badge">1</span> <i class="fa fa-exclamation-circle icon"></i> new registration
                        </li>
                    </a>
                    <a href="#">
                        <li class="list-group-item">
                            <span class="badge success">1</span> <i class="fa fa-check icon"></i> new orders
                        </li>
                    </a>
                    <a href="#">
                        <li class="list-group-item">
                            <span class="badge danger">2</span> <i class="fa fa-comments icon"></i> customers messages
                        </li>
                    </a>
                    <a href="#">
                        <li class="list-group-item message">
                            view all
                        </li>
                    </a>
                </ul>
            </li>
        </ul>
    </li>
    <li class="dropdown profile">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Emily Hart <span class="caret"></span></a>
        <ul class="dropdown-menu animated fadeInDown">
            <li class="profile-img">
                <img src="../lib/img/profile/picjumbo.com_HNCK4153_resize.jpg" class="profile-img">
            </li>
            <li>
                <div class="profile-info">
                    <h4 class="username">Emily Hart</h4>
                    <p>emily_hart@email.com</p>
                    <div class="btn-group margin-bottom-2x" role="group">
                        <button type="button" class="btn btn-default"><i class="fa fa-user"></i> Profile</button>
                        <button type="button" class="btn btn-default"><i class="fa fa-sign-out"></i> Logout</button>
                    </div>
                </div>
            </li>
        </ul>
    </li>
  </ul>`,
  data:function(){
    return {}
  }
})
var navData = {
    accNav1:'organization',
    accNav2:'organization-base',
    accNav3:'0',
    nav1:[
        {id:'0',name:'组织管理',type:'organization',fa:'fa-users'},
        {id:'1',name:'设备管理',type:'device',fa:'fa-wrench'},
        {id:'2',name:'量化任务',type:'quantitave',fa:'fa-trophy'},
        {id:'3',name:'信息管理',type:'info',fa:'fa-comment'},
        {id:'4',name:'作业管理',type:'task',fa:'fa-road'},
        {id:'5',name:'应急处置',type:'emergency',fa:'fa-bolt'}
    ],
    nav2:[
        {id:'0-0',url:'./organization-base-depsetting.html',name:'基础信息',type:'organization'},
        {id:'0-1',url:'./organization-people-base.html',name:'人员信息管理',type:'organization'},
        {id:'0-2',url:'./organization-grid-manage.html',name:'网格管理',type:'organization'},
        {id:'1-0',url:'./device-base.html',name:'设备信息',type:'device'},
        {id:'2-0',url:'./quantitave-manage.html',name:'任务管理',type:'quantitave'},
        {id:'3-0',url:'./info-manage.html',name:'信息分类',type:'info'},
        {id:'4-0',url:'./task-flow.html',name:'作业流程管理',type:'task'},
        {id:'4-1',url:'./task-base.html',name:'作业任务管理',type:'task'},
        {id:'4-2',url:'./task-train-info.html',name:'列车信息管理',type:'task'},
        {id:'5-0',url:'./emergency-base.html',name:'应急处置管理',type:'emergency'}
    ],
    nav3:[
        {id:'0',url:'./organization-base-depsetting.html',name:'部门设置','type':'organization-base'},
        {id:'1',url:'./organization-base-role.html',name:'角色设置','type':'organization-base'},
        {id:'2',url:'./organization-base-station.html',name:'岗位设置','type':'organization-base'},
        {id:'3',url:'./organization-base-info.html',name:'组织信息','type':'organization-base'},
        {id:'4',url:'./organization-people-base.html',name:'人员信息管理','type':'organization-people'},
        {id:'5',url:'./organization-grid-manage.html',name:'网格管理','type':'organization-grid'},
        {id:'6',url:'./device-base.html',name:'设备信息','type':'device'},
        {id:'7',url:'./device-type.html',name:'设备类型','type':'device'},
        {id:'8',url:'./quantitave-manage.html',name:'任务管理','type':'quantitave'},
        {id:'9',url:'./info-manage.html',name:'信息上报','type':'info'},
        {id:'10',url:'./task-flow.html',name:'作业流程管理','type':'task-flow'},
        {id:'11',url:'./task-base.html',name:'作业任务管理','type':'task-base'},
        {id:'12',url:'./task-train-info.html',name:'列车信息管理','type':'task-train'},
        {id:'13',url:'./task-train-station.html',name:'站名管理','type':'task-train'},
        {id:'14',url:'./emergency-base.html',name:'应急处置管理','type':'emergency'}
    ]
}
